<template>
	<view>
		<view class="header">
			<image src="../../static/index-banner.png" mode="" class="headertub"></image>
			<view @tap="selectClass" class="class-box">{{class_info.class_name}}</view>
		</view>
		<!-- 通知栏 -->
		<view class="message">
			<image src="../../static/index_notice.gif" mode="" class="message-tub"></image>
			<view class="message-txt">
				通知：五一放假时间为2021年5月1日——2021年5月5日
			</view>
		</view>
		<view class="message-item" >
			<view v-for="(item,index) in menu" class="items" :key="index" @click="gopage(item.path)">
				<image :src="item.img" mode="" class="item-tub" :key="imgindex"></image>
				<view class="item-txt">{{item.name}}</view>
			</view>
		</view>
		<view>
		</view>
		
	</view>
</template>

<script>
	const {appLogin,httpGet,httpPost,msg,ZC} = require("@/utils/common.js")
	let app = getApp();
	export default {
		data() {
			return {
				imgindex:0,
				// listindex:0,
				menu:[],
				class_info:{},
				class_name: "",
				// 给每个身份安排一个菜单
				list_student:[
					{
						path:'/pages/student/class-detail',
						img:"../../static/index_my_class.gif",
						name:'我的班级',
					},
					{
						path:'/pages/rollcall/index',
						img:"../../static/index_rollcall.gif",
						name:'上课点名'
					},
					{
						path:'/pages/leave/apply',
						img:"../../static/index_leave_apply.gif",
						name:'请假申请'
					},
					// {
					// 	path:'/pages/exam/index',
					// 	img:"../../static/index_exam.gif",
					// 	name:'考试分数'
					// },
					{
						path:'/pages/exam/student_list',
						img:"../../static/index_exam.gif",
						name:'考试列表'
					},
					{
						path:'/pages/index/myfile',
						img:"../../static/index_myfile.gif",
						name:'我的资料'
					},
				],
				list_course_student:[
					{
						path:'/pages/student/info',
						img:"../../static/index_my_class.gif",
						name:'我的班级',
					},
					{
						path:'/pages/rollcall/index',
						img:"../../static/index_rollcall.gif",
						name:'上课点名'
					},
					// {
					// 	path:'/pages/leave/apply',
					// 	img:"../../static/index_leave_apply.gif",
					// 	name:'请假申请'
					// },
					// {
					// 	path:'/pages/exam_input/index',
					// 	img:"../../static/index_exam.gif",
					// 	name:'考试分数'
					// },
					
					{
						path:'/pages/exam/course_teacher_list',
						img:"../../static/index_exam.gif",
						name:'考试列表'
					},
					
					{
						path:'/pages/index/myfile',
						img:"../../static/index_myfile.gif",
						name:'我的资料'
					},
					// {
					// 	path:'/pages/leave/record',
					// 	img:"../../static/index_leave_record.gif",
					// 	name:'请假审批'
					// },
					
				],
				list_teacher:[
					{
						path:'/pages/student/info',
						img:"../../static/index_my_class.gif",
						name:'我的班级',
					},
					// {
					// 	path:'/pages/rollcall/index',
					// 	img:"../../static/index_rollcall.gif",
					// 	name:'上课点名'
					// },
					// {
					// 	path:'/pages/leave/apply',
					// 	img:"../../static/index_leave_apply.gif",
					// 	name:'请假申请'
					// },
					// {
					// 	path:'/pages/exam_input/index',
					// 	img:"../../static/index_exam.gif",
					// 	name:'考试分数'
					// },
					{
						path:'/pages/teacher/info',
						img:"../../static/index_myfile.gif",
						name:'我的资料'
					},
					{
						path:'/pages/leave/record',
						img:"../../static/index_leave_record.gif",
						name:'请假审批'
					},
					{
						path:'/pages/exam/teacher_list',
						img:"../../static/index_exam.gif",
						name:'考试列表'
					},
					// {
					// 	path:'/pages/exam_input/index',
					// 	img:"../../static/index_exam_input.gif",
					// 	name:'录入分数'
					// },
				]
				
			}
		},
		onLoad(){
			appLogin((user_info)=>{
				if(user_info.student_id && user_info.student){
					app.globalData.class_id = user_info.student.class_id
					this.menu = this.list_student
				}
				if(user_info.course_teacher_list && user_info.course_teacher_list.length>0){
					app.globalData.course_teacher_info = user_info.course_teacher_list[0]
					app.globalData.class_id = user_info.course_teacher_list[0].class_id
					
					this.menu = this.list_course_student
				}
				if(user_info.teacher_id && user_info.teacher){
					app.globalData.teacher_info = user_info.teacher
					app.globalData.class_id = user_info.teacher.class[0].class_id
					
					this.menu = this.list_teacher
				}
				this.user_info = user_info
				
			})
		},
		onShow(){
			if(app.globalData.class_info){
				this.class = app.globalData.class_info
				this.class_name = this.class.class_name
			}
			if(app.globalData.target_info && app.globalData.target_info.course_teacher_id){
				this.menu = this.list_course_student
			}
			else if(app.globalData.target_info && app.globalData.target_info.teacher_id){
				this.menu = this.list_teacher
			}
			
			if(app.globalData.class_id){
				this.class_id = app.globalData.class_id;
				this.getClassInfo()
			}
		},
		methods: {
			gopage(url){
				// console.log(url)
				uni.navigateTo({
					url
				})
			},
			getClassInfo(){
				httpGet({
					url:"users/class/info",
					data:{
						class_id:this.class_id
					}
				}).then((res)=>{
					this.class_info = res.result.info
					console.log(this.class_info)
				})
			},
			selectClass(){
				if(this.user_info.teacher_id || this.user_info.course_teacher_info){
					uni.navigateTo({
						url:"select_class"
					})
				}
			}
				
		}
	}
</script>

<style scoped>
	.header{
		width: 690rpx;
		height: 332rpx;
		margin-left: 30rpx;
	}
	.headertub{
		width: 100%;
		height: 100%;
		float: left;
		/* position: fixed; */
		border-radius: 10rpx;
	}
	.class-box{
		min-width: 174rpx;
		height: 45rpx;
		border-radius: 25rpx;
		font-size: 24rpx;
		line-height: 45rpx;
		position: absolute;
		padding: 0 20rpx;
		top: 20rpx;
		right: 40rpx;
		background-color: #3679d9;
		text-align: center;
		color: white;
	}
	.message{
		height: 63rpx;
		width: 690rpx;
		margin-left: 30rpx;
		background-color: #f2f8ff;
		border-radius: 10rpx;
		margin-top: 30rpx;
	}
	.message-tub{
		width: 30rpx;
		height: 30rpx;
		margin-left: 25rpx;
		margin-top: 18rpx;
		float: left;
	}
	.message-txt{
	line-height: 63rpx;
	position: relative;
	font-size: 20rpx;
	margin-left: 75rpx;
	}
	.message-item{
		height: 365rpx;
		width: 670rpx;
		margin-left: 30rpx;
	}
	.items{
		width: 25%;
		height: 142rpx;
		float: left;
		margin-top: 87rpx;
	}
	.item-tub{
		width: 95rpx;
		height: 95rpx;
		margin-left: 40rpx;
		border-radius: 50%;
	}
	.item-txt{
		font-size: 25rpx;
		
		text-align: center;
		/* margin-left: 95rpx; */
	}
</style>
